﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StockFinder.HistoricalPriceAnalysers;
using StockFinder.DataAccess;
using System.IO;

namespace StockFinder.Applications.Main
{
    public partial class PriceMoveFinderTestForm : Form
    {
        public PriceMoveFinderTestForm()
        {
            InitializeComponent();
        }

        private void _Scenario1Button_Click(object sender, EventArgs e)
        {
            var analyser = new EveryPriceMoveFinderHistoricalPriceAnalyser();
            var results = new List<HistoricPriceAnalyserResult>();
            var prices = DailyPriceDataAccess.GetAllDailyPricesBySymbol("AAPL");

            //look for draw downs between 5 and 20
            for (decimal i = 5; i < 20; i += 0.5M)
            {
                results.AddRange(analyser.AnalysePrices(prices, i));
            }

            var output = new StringBuilder();
            output.AppendLine("Date,High,Drawdown,Days");
            results.ForEach(r => output.AppendLine(
                string.Format("{0},{1},{2},{3}", r.LastPriceDate, r.DepthFromHigh, r.BaseDepth, r.BaseLength)));

            File.WriteAllText("AAPLEveryMoves.csv", output.ToString());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var analyser = new ContinuousPriceMoveFinderHistoricalPriceAnalyser();            

            var prices = DailyPriceDataAccess.GetAllDailyPricesBySymbol("AAPL");

            var output = new StringBuilder();
            output.AppendLine("Date,High,Drawdown,Days,MaxDD");

            //look for draw downs between 5 and 20
            for (decimal i = 5; i < 20; i += 0.5M)
            {
                var results = analyser.AnalysePrices(prices, i) ;

                results.ForEach(r => output.AppendLine(
                    string.Format("{0},{1},{2},{3},{4}", r.LastPriceDate, r.DepthFromHigh, r.BaseDepth, r.BaseLength, i)));
            }                                    

            File.WriteAllText("AAPLContinuousMoves.csv", output.ToString());
        }
    }
}
